package com.glhtgyxy.biyesheji.Controller;

import com.glhtgyxy.biyesheji.Pojo.evaluate;
import com.glhtgyxy.biyesheji.Pojo.house;
import com.glhtgyxy.biyesheji.Pojo.merchant;
import com.glhtgyxy.biyesheji.Pojo.user;
import com.glhtgyxy.biyesheji.Service.clientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("client")
@CrossOrigin(origins = "*")
public class clientController {

    @Autowired
    clientService service;

    @ResponseBody
    @RequestMapping("findhouse/{addr}/{price}/{bedroom}/{search}")
    public ArrayList<house> findHouse(
            @PathVariable String  addr,
            @PathVariable String  price,
            @PathVariable String  bedroom,
            @PathVariable String  search
    ){
        System.out.println("开始条件查询房屋:"+addr+price+bedroom+search);
        ArrayList<house> houses = service.findHouse(addr,price,bedroom,search);
        System.out.println("条件查询结束，返回:"+houses);
        return houses;
    }

    @ResponseBody
    @RequestMapping("findhousebyid/{id}")
    public ArrayList<house> findHouseById(
            @PathVariable int  id
    ){
        System.out.println("开始id查询房屋:"+id);
        ArrayList<house> houses = service.findHouseById(id);
        System.out.println("id查询结束，返回:"+houses);
        return houses;
    }

    @ResponseBody
    @RequestMapping("houseidfindmaser/{id}")
    public ArrayList<merchant> houseIdFindMaser(
            @PathVariable int  id
    ){
        System.out.println("房屋id查询主人中:"+id);
        ArrayList<merchant> merchant = service.houseIdFindMaser(id);
        System.out.println("查询结束，返回:"+merchant);
        return merchant;
    }

    @ResponseBody
    @RequestMapping("merchantidfindevaluate/{id}")
    public ArrayList<evaluate> merchantIdFindEvaluate(
            @PathVariable int  id
    ){
        System.out.println("主人id查询评论中:"+id);
        ArrayList<evaluate> eva = service.merchantIdFindEvaluate(id);
        System.out.println("查询结束，返回:"+eva);
        return eva;
    }

    @ResponseBody
    @RequestMapping("useridfinduser/{id}")
    public ArrayList<user> evaFindUser(
            @PathVariable int  id
    ){
        System.out.println("评论查询用户中:"+id);
        ArrayList<user> eva = service.evaFindUser(id);
        System.out.println("查询结束，返回:"+eva);
        return eva;
    }

    @ResponseBody
    @RequestMapping("tijiaodingdan/{houseid}/{userid}/{checkInDate}/{checkOutDate}")
    public boolean tijiaodingdan(
            @PathVariable int  houseid,
            @PathVariable int  userid,
            @PathVariable String  checkInDate,
            @PathVariable String  checkOutDate
    ){
        System.out.println("添加订单中，用户id:"+userid+"房屋id："+houseid+"入住时间："+checkInDate+"退房时间："+checkOutDate);
        boolean bl;
        bl = true;
        bl = service.tijiaodingdan(houseid,userid,checkInDate,checkOutDate);
        System.out.println("添加订单方法结束，返回:"+bl);
        return bl;
    }




}
